package com.hdoit.ares.logical.order.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.tennetcn.common.dao.base.impl.SuperService;
import com.tennetcn.common.enums.ModelStatus;
import com.tennetcn.common.utils.CommonUtils;
import com.tennetcn.common.utils.DateUtils;
import com.hdoit.ares.logical.acc.model.AccountInfo;
import com.hdoit.ares.logical.acc.model.GoldenBeanDetail;
import com.hdoit.ares.logical.acc.service.IAccountInfoService;
import com.hdoit.ares.logical.acc.service.IGoldenBeanDetailService;
import com.hdoit.ares.logical.acc.service.IGoldenBeanInfoService;
import com.hdoit.ares.logical.acc.service.IIncomeDetailService;
import com.hdoit.ares.logical.acc.service.IIncomeInfoService;
import com.hdoit.ares.logical.acc.service.impl.AccountInfoServiceImpl;
import com.hdoit.ares.logical.order.model.OrderInfo;
import com.hdoit.ares.logical.order.service.IOrderInfoService;
import com.hdoit.ares.selfcommon.enums.acc.HesitatePeriodState;
import com.hdoit.ares.selfcommon.enums.acc.State;
/**
 * @author      yujinhui
 * @email       
 * @createtime  2018年02月06日 10:50:26
 * @comment
 */
@Component
public class OrderInfoServiceImpl extends SuperService<OrderInfo> implements IOrderInfoService{
	private IAccountInfoService accountInfoService;
	public IAccountInfoService getAccountInfoService() {
		return accountInfoService;
	}
	@Resource
	public void setAccountInfoService(IAccountInfoService accountInfoService) {
		this.accountInfoService = accountInfoService;
	}
	
	private IGoldenBeanDetailService goldenBeanDetailService;
	public IGoldenBeanDetailService getGoldenBeanDetailService() {
		return goldenBeanDetailService;
	}
	@Resource
	public void setGoldenBeanDetailService(IGoldenBeanDetailService goldenBeanDetailService) {
		this.goldenBeanDetailService = goldenBeanDetailService;
	}
	
	private IIncomeInfoService incomeInfoService;
	public IIncomeInfoService getIncomeInfoService() {
		return incomeInfoService;
	}
	@Resource
	public void setIncomeInfoService(IIncomeInfoService incomeInfoService) {
		this.incomeInfoService = incomeInfoService;
	}
	
	private IIncomeDetailService incomeDetailService;
	public IIncomeDetailService getIncomeDetailService() {
		return incomeDetailService;
	}
	@Resource
	public void setIncomeDetailService(IIncomeDetailService incomeDetailService) {
		this.incomeDetailService = incomeDetailService;
	}
	
	
	@Override
	public boolean applyChangeState(String orderId) {
		OrderInfo orderInfo = queryModel(orderId);
		orderInfo.setOrderStatus("");
		return updateModel(orderInfo);
	}

	@Override
	public boolean addPayInfo(String orderId,String customerId) {
		OrderInfo orderInfo = queryModel(orderId);
		
		//如果用金豆支付了就产生金豆明细，同时减去账户相应的金豆数
		if(orderInfo.getGoldBean() > 0){
			AccountInfo accountInfo = accountInfoService.queryModelByCustomerId(customerId);
			accountInfo.setModelStatus(ModelStatus.update);
			accountInfo.setGoldenBean(accountInfo.getGoldenBean() - orderInfo.getGoldBean());
			
			//添加金豆明细
			GoldenBeanDetail goldenBeanDetail = new GoldenBeanDetail();
			goldenBeanDetail.setId(CommonUtils.getKeyId());
			goldenBeanDetail.setAccountNo(accountInfo.getAccountNo());
			goldenBeanDetail.setTime(DateUtils.getCurrent());
			goldenBeanDetail.setState(State.pay);
			goldenBeanDetail.setGoldenBeanAccount(orderInfo.getGoldBean());
			goldenBeanDetail.setGoldenBeanBalance(accountInfo.getGoldenBean());
			goldenBeanDetail.setCustomerId(customerId);
			goldenBeanDetail.setOutTradeNo(orderId);
			goldenBeanDetail.setPaymentNo(orderId);
			goldenBeanDetail.setHesitatePeriod(7);
			goldenBeanDetail.setHesitatePeriodState(HesitatePeriodState.Hesitated);
			goldenBeanDetail.setModelStatus(ModelStatus.add);
		}
		
		//如果用奖金支付就产生奖金明细，同时减去账户相应的奖金数
		if(orderInfo.getIncome() > 0){
			
		}
		

		return false;
	}
	
}